package net.qhzw.admin.service.impl;


import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeUtil;
import net.qhzw.admin.entity.SysArea;
import net.qhzw.admin.mapper.SysAreaMapper;
import net.qhzw.admin.pojo.AreaVo;
import net.qhzw.admin.service.SysAreaService;
import net.qhzw.common.model.JsonResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SysAreaServiceImpl implements SysAreaService {


    @Autowired
    private SysAreaMapper areaMapper;

    /**
     * 根据父级code查询地区
     * @param pcode
     * @return 地区列表
     */
    @Override
    public JsonResult getArea(Long pcode) {
        List<SysArea> list = areaMapper.selectByPcode(pcode);
        List<AreaVo> areaVos = new ArrayList<>();
        for (SysArea sysArea : list) {
            AreaVo areaVo = new AreaVo();
            BeanUtils.copyProperties(sysArea, areaVo);
            if (areaVo.getLevel() == 5){
                areaVo.setHasChildren(false);
            }else {
                areaVo.setHasChildren(true);
            }
            areaVos.add(areaVo);
        }

        return JsonResult.success(areaVos);
    }




}
